package com.dpwgc.consumer.config;

import com.dpwgc.consumer.interceptor.LoadBalancedInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 注册拦截器
 */
@CrossOrigin
@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter
{

    @Bean
    public LoadBalancedInterceptor getLoginInterceptor(){
        return new LoadBalancedInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(getLoginInterceptor());
        registration.addPathPatterns("/**");                      //所有路径都被拦截
        registration.excludePathPatterns(                         //添加不拦截路径
                "/Consumer/**",
                "/favicon.ico"
        );
    }
}